import asyncio
import functools
import time
from typing import Callable, Any

import aiohttp


def async_timed():
    def wrapper(func: Callable):
        @functools.wraps(func)
        async def wrapped(*args: Any, **kwargs: Any) -> Any:
            print(f"有参数{args}，{kwargs}的函数{func}开始运行")
            start = time.time()
            try:
                return await func(*args, **kwargs)
            finally:
                end = time.time()
                total = end - start
                print(f"函数{func}总共花费时间：{total}s")

        return wrapped

    return wrapper


async def fetch_status(session, url, sleep_time=0, timeout=1):
    await asyncio.sleep(sleep_time)
    # 超时时间设置，总超时时间为0.1s
    ten_millis = aiohttp.ClientTimeout(total=timeout)
    async with session.get(url, timeout=ten_millis) as result:
        return result.status
